﻿using System;
using System.Web.Security;

public partial class UI_signup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSignup_click(object sender, EventArgs e)
    {
        if (chkterms.Checked)
        {
            if (/*Membership.FindUsersByName(txtUsername.Text.Trim()).Count == 0*/true)
            {
                MembershipCreateStatus status = new MembershipCreateStatus();
                BintjeMembershipUser memuser = Membership.CreateUser(txtUsername.Text.Trim(), txtEmail.Text.Trim(), txtEmail.Text.Trim(), "Q", "a", true, out status) as BintjeMembershipUser;
                switch (status)
                {
                    case MembershipCreateStatus.Success:
                        Session["UserId"] = memuser.userID;
                        lblSignupMsg.Text = "User created successfully!!";
                        //FormsAuthentication.SetAuthCookie(txtUsername.Text.Trim(), true);
                        Response.Redirect("~/Login.aspx");
                        break;
                    case MembershipCreateStatus.DuplicateUserName:
                        lblSignupMsg.Text = "Nick Name already exist, please try other";
                        break;
                    case MembershipCreateStatus.InvalidPassword:
                        lblSignupMsg.Text = "Password must be greater than 6 characters";
                        break;
                    case MembershipCreateStatus.InvalidUserName:
                        lblSignupMsg.Text = "Login must be an unique valid e-mail address";
                        break;
                    default:
                        break;
                }
            }
            else
            {
                lblSignupMsg.Text = "nick name already exist, please try other";
            }
        }
        else
        {
            lblSignupMsg.Text = "You must accept \"terms of service\" before signup";
        }
    }
}
